home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include "defines.h"
- #include "event.h"
- #include "snurb.h"
- #include "draw.h"
- #include "matrix.h"
- #include "menu.h"
- #include "pick.h"
- #include "rotate.h"
- #include "data.h"
- #include "scaleobj.h"
- #include "rotobj.h"
- #include "spaced.h"
- #include "nurb.h"
- #include "zip.h"
- #include "control.h"
-
-
-
- /* motion */
- Boolean
- moving_control,
- moving_object,
- rotating_view,
- rotating_object,
- scaling_object,
- zipping;
-
- static Coord motion_origin[3];
- int move_s,move_t;
-
- extern Boolean euler_initialized;
-
- /* viewing and projection all in one tidy matrix */
- static Matrix everything_matrix;
-
- extern Matrix identity_matrix;
-
- /* which tool is in use */
- int tool;
-
- struct node_struct *selected_patch;
- extern struct node_struct *root;
-
- /* window information */
- extern long origin_x, origin_y;
- extern long size_x, size_y;
- extern float aspect;
-
- /* rotation */
- extern Matrix view_matrix;
- extern Matrix R_view_matrix;
-
- /* limits of space editor motion */
- Coord spaced_limit[3][2] =
- { { -1.0, 1.0},
- { -1.0, 1.0},
- { -1.0, 1.0}
- };
-
-
- struct node_struct *zip_source, *zip_dest;
- int source_s, source_t, dest_s, dest_t;
-
-
-
- /* Called every MOUSEX and MOUSEY event, if we are looking for them */
- void process_mouse_motion(void)
- {
- Coord offset[3];
- Matrix object_matrix;
-
- if (moving_control && getbutton(LEFTMOUSE))
- {
- if (selected_patch != NULL)
- {
- spaced_limit[0][0] = selected_patch->patch->control[move_s][move_t][0] - .2;
- spaced_limit[0][1] = selected_patch->patch->control[move_s][move_t][0] + .2;
-
- spaced_limit[1][0] = selected_patch->patch->control[move_s][move_t][1] - .2;
- spaced_limit[1][1] = selected_patch->patch->control[move_s][move_t][1] + .2;
-
- spaced_limit[2][0] = selected_patch->patch->control[move_s][move_t][2] - .2;
- spaced_limit[2][1] = selected_patch->patch->control[move_s][move_t][2] + .2;
-
-
-
- spaced(everything_matrix,
- selected_patch->patch->control[move_s][move_t],
- spaced_limit);
-
- clear_zip_effects(root->child);
- move_zipped_points(selected_patch, move_s, move_t);
-
- clear_zip_effects(root->child);
- move_zipped_points(selected_patch, move_s, move_t);
-
- draw_display();
- }
- }
- else if (moving_object && getbutton(LEFTMOUSE))
- {
- offset[0] = motion_origin[0];
- offset[1] = motion_origin[1];
- offset[2] = motion_origin[2];
-
- spaced_limit[0][0] = motion_origin[0] - .2;
- spaced_limit[0][1] = motion_origin[0] + .2;
-
- spaced_limit[1][0] = motion_origin[1] - .2;
- spaced_limit[1][1] = motion_origin[1] + .2;
-
- spaced_limit[2][0] = motion_origin[2] - .2;
- spaced_limit[2][1] = motion_origin[2] + .2;
-
- spaced(everything_matrix, motion_origin, spaced_limit);
-
- offset[0] = motion_origin[0] - offset[0];
- offset[1] = motion_origin[1] - offset[1];
- offset[2] = motion_origin[2] - offset[2];
-
- pushmatrix();
- loadmatrix(identity_matrix);
- translate(offset[0], offset[1], offset[2]);
- getmatrix(object_matrix);
- popmatrix();
-
- update_selected_children(root->child, object_matrix);
- draw_display();
- }
- else if (rotating_view && getbutton(MIDDLEMOUSE))
- {
- update_view_rotation();
- draw_display();
- }
- else if (rotating_object && getbutton(MIDDLEMOUSE))
- {
- update_object_rotation(object_matrix);
-
- update_selected_children(root->child, object_matrix);
- draw_display();
- }
- else if (scaling_object && getbutton(LEFTMOUSE))
- {
- update_object_scale(object_matrix);
-
- update_selected_children(root->child, object_matrix);
- draw_display();
- }
- }
-
-
-
-
- void deselect_children(struct node_struct *child)
- {
- if (child != NULL)
- {
- child->selected = FALSE;
- deselect_children(child->sibling);
- }
- }
-
-
-
- /* Where we go on middle down events */
- void process_middle_down(void)
- {
- Scoord mx,my;
- struct node_struct *selected_object, *rootmost_parent;
-
- /* Mouse position in window screen coords */
- mx = getvaluator(MOUSEX) - (Scoord)origin_x;
- my = getvaluator(MOUSEY) - (Scoord)origin_y;
-
- selected_object = pick_object(mx, my);
-
- if (selected_object == NULL)
- {
- rotating_view = TRUE;
- rotate_view_volume();
- }
- else
- {
- if (! (getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY)))
- deselect_children(root->child);
-
- rootmost_parent = find_rootmost_parent(selected_object);
-
- rootmost_parent->selected = TRUE;
-
- rotating_object = TRUE;
- rotate_object();
- }
-
- qdevice(MOUSEX);
- qdevice(MOUSEY);
- }
-
-
- /* Where we go on middle up events */
- void process_middle_up(void)
- {
- unqdevice(MOUSEX);
- unqdevice(MOUSEY);
-
- rotating_view = FALSE;
- rotating_object = FALSE;
- }
-
-
- /* Where we go on left up events */
- void process_left_up(void)
- {
- unqdevice(MOUSEX);
- unqdevice(MOUSEY);
-
- moving_control = FALSE;
- moving_object = FALSE;
- scaling_object = FALSE;
-
- end_spaced();
-
- draw_display();
- }
-
-
- /* Process a left mouse button down event */
- void process_left_down(void)
- {
- Scoord mx,my;
- struct node_struct *selected_object, *rootmost_parent;
-
-
- /* Mouse position in window screen coords */
- mx = getvaluator(MOUSEX) - (Scoord)origin_x;
- my = getvaluator(MOUSEY) - (Scoord)origin_y;
-
- selected_patch = pick_patch_control(root->child,mx,my,&move_s, &move_t);
-
- if (selected_patch != NULL)
- {
- rootmost_parent = find_rootmost_parent(selected_patch);
-
- if (rootmost_parent->selected)
- set_operation();
- else
- {
- selected_object = pick_object(mx,my);
-
- if (! (getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY)))
- deselect_children(root->child);
-
- if (selected_object != NULL)
- {
- rootmost_parent = find_rootmost_parent(selected_object);
- rootmost_parent->selected = TRUE;
- }
- else
- {
- zipping = FALSE;
- zip_dest = NULL;
- }
- }
- }
- else
- {
- selected_object = pick_object(mx,my);
-
- if (! (getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY)))
- deselect_children(root->child);
-
- if (selected_object != NULL)
- {
- rootmost_parent = find_rootmost_parent(selected_object);
- rootmost_parent->selected = TRUE;
- }
- else
- {
- zipping = FALSE;
- zip_dest = NULL;
- }
- }
-
- draw_display();
- }
-
-
- void set_operation()
- {
- switch(tool)
- {
- case EDIT_TOOL:
- moving_control = TRUE;
-
- qdevice(MOUSEX);
- qdevice(MOUSEY);
-
- mmode(MSINGLE);
- set_view(MSINGLE);
- multmatrix(view_matrix);
- getmatrix(everything_matrix);
-
- spaced_limit[0][0] = selected_patch->patch->control[move_s][move_t][0] - .2;
- spaced_limit[0][1] = selected_patch->patch->control[move_s][move_t][0] + .2;
-
- spaced_limit[1][0] = selected_patch->patch->control[move_s][move_t][1] - .2;
- spaced_limit[1][1] = selected_patch->patch->control[move_s][move_t][1] + .2;
-
- spaced_limit[2][0] = selected_patch->patch->control[move_s][move_t][2] - .2;
- spaced_limit[2][1] = selected_patch->patch->control[move_s][move_t][2] + .2;
-
- start_spaced();
- break;
-
- case MOVE_TOOL:
- moving_object = TRUE;
-
- motion_origin[0]=selected_patch->patch->control[move_s][move_t][0];
- motion_origin[1]=selected_patch->patch->control[move_s][move_t][1];
- motion_origin[2]=selected_patch->patch->control[move_s][move_t][2];
-
- qdevice(MOUSEX);
- qdevice(MOUSEY);
-
- mmode(MSINGLE);
- set_view(MSINGLE);
- multmatrix(view_matrix);
- getmatrix(everything_matrix);
-
- spaced_limit[0][0] = motion_origin[0] - .2;
- spaced_limit[0][1] = motion_origin[0] + .2;
-
- spaced_limit[1][0] = motion_origin[1] - .2;
- spaced_limit[1][1] = motion_origin[1] + .2;
-
- spaced_limit[2][0] = motion_origin[2] - .2;
- spaced_limit[2][1] = motion_origin[2] + .2;
-
- start_spaced();
- break;
-
- case SCALE_TOOL:
- scaling_object = TRUE;
-
- scale_object();
-
- qdevice(MOUSEX);
- qdevice(MOUSEY);
- break;
-
- case SHARP_ZIP_TOOL:
- process_zip();
- break;
-
- case SMOOTH_ZIP_TOOL:
- process_zip();
- break;
-
- case ROUND_ZIP_TOOL:
- process_zip();
- break;
-
- case UNZIP_TOOL:
- if (inner_edge(move_s,move_t))
- unzip_edge(selected_patch,find_zip_edge(move_s,move_t));
- break;
-
- default:
- fprintf(stderr,"Uh Oh. Unknown Tool\n");
- break;
-
- }
- }
-
-
- void process_zip(void)
- {
- struct node_struct *source_parent, *dest_parent;
-
- if (! zipping)
- {
- if (inner_edge(move_s,move_t))
- {
- zipping = TRUE;
-
- zip_dest = selected_patch;
- dest_s = move_s;
- dest_t = move_t;
-
- draw_display();
- }
- }
- else
- {
- if ((selected_patch != zip_dest) && (inner_edge(move_s,move_t)))
- {
- zip_source = selected_patch;
- source_s = move_s;
- source_t = move_t;
-
- clear_zip_effects(root->child);
-
- zip_patches(
- zip_source,
- zip_dest,
- source_s, source_t,
- dest_s, dest_t,
- tool);
-
- source_parent = find_rootmost_parent(zip_source);
- dest_parent = find_rootmost_parent(zip_dest);
-
- /* if not already grouped, group 'em */
- if (source_parent != dest_parent)
- {
- deselect_children(root->child);
- source_parent->selected = TRUE;
- dest_parent->selected = TRUE;
- group();
- }
-
- zipping = FALSE;
- zip_dest = NULL;
- }
- }
- }
-
-
-
-
-
-
- void update_selected_children(struct node_struct *child, Matrix mat)
- {
- if (child != NULL)
- {
- if (child->selected)
- update_control_points(child, mat);
-
- update_selected_children(child->sibling, mat);
- }
- }
-
-
-
-
- /*********** MENU FUNCTIONS **************/
-
-
-
- void set_defaults(void)
- {
- tool = MOVE_TOOL;
- selected_patch = NULL;
- deselect_children(root->child);
-
- make_identity(view_matrix);
- make_identity(R_view_matrix);
- euler_initialized = FALSE;
-
- moving_control =
- moving_object =
- rotating_view =
- rotating_object =
- scaling_object =
- zipping = FALSE;
-
- selected_patch = zip_dest = NULL;
-
- draw_display();
-
- remake_all_menus();
- }
-
-
- /*
- * Changes the tool to that selected by the user.
- */
- void change_tool(int new_tool)
- {
- tool = new_tool;
-
- remake_tool_menu();
- remake_snurb_menu();
- }
-
-
-
- void delete_selected_children(struct node_struct *child)
- {
- struct node_struct *next_child;
-
- if (child != NULL)
- {
- next_child = child->sibling;
-
- if (child->selected)
- free_object(child);
-
- delete_selected_children(next_child);
- }
- }
-
-
-
- void delete_object(void)
- {
- delete_selected_children(root->child);
-
- moving_control =
- moving_object =
- rotating_view =
- rotating_object =
- scaling_object =
- zipping = FALSE;
-
- selected_patch = zip_dest = NULL;
-
- draw_display();
- }
-
-
- void select_all_root_children(struct node_struct *child)
- {
- if (child != NULL)
- {
- child->selected = TRUE;
- select_all_root_children(child->sibling);
- }
- }
-
-
- void select_all(void)
- {
- select_all_root_children(root->child);
- draw_display();
- }
-
-
-
- /* Take all of the root-level nodes that have selected==TRUE and
- * group them beneath one new parent, root-level node
- */
- void group(void)
- {
- group_selected_children(root);
- }
-
-
- void ungroup(void)
- {
- ungroup_selected_children(root->child);
- }
-
-
-
-
-
-
-
-
- #ifdef spaceball
- /* ================== SPACEBALL INTERFACE ROUTINES ====================== */
-
-
- /* ==================== spcbal_do ========================== */
- /* This routine is called by sbinteg.c when a Spaceball event has
- * occurred. This routine will use this information to manipulate
- * a viewing matrix.
- */
-
- void spcbal_do(rotvec, rotscale, transvec, transcale)
- Coord rotvec[ 3 ];
- float rotscale;
- Coord transvec[ 3 ];
- float transcale;
- /*
- void spcbal_do(
- Coord rotvec[ 3 ],
- float rotscale,
- Coord transvec[ 3 ],
- float transcale) DEFINING IT THIS WAY MAKES IT CORE DUMP !! */
- {
-
- Matrix object_matrix;
- int i;
- Coord center[3];
-
- /* Apply the incremental rotation and translation to the
- * viewing rotation matrix and translation vector
- */
-
- if (root->child != NULL)
- {
- make_identity(object_matrix);
-
- sbMapply(
- object_matrix, /* The viewing matrix */
- (Coord) 1.0, /* The field of view */
- (Coord) 1.0, /* The aspect ratio */
- (Coord) .5, /* The object radius */
- rotvec, /* Passed Rotation vector */
- rotscale, /* Passed Rotation scale */
- transvec, /* Passed Translation vector */
- transcale /* Passed Translation scale */
- );
-
-
- compute_center(center);
-
- loadmatrix(identity_matrix);
-
- translate(center[0],center[1],center[2]);
- multmatrix(R_view_matrix);
- rotate(450,'y');
- rotate(-450,'x');
- multmatrix(object_matrix);
- rotate(450,'x');
- rotate(-450,'y');
- multmatrix(view_matrix);
- translate(-center[0],-center[1],-center[2]);
-
-
- getmatrix(object_matrix);
-
- update_selected_children(root->child, object_matrix);
-
- draw_display();
- }
- }
-
-
-
- /* ====================== spchome ====================== */
- /* This routine is called when the user requests that the image
- * is reset to the initial position. This usually means setting
- * the viewing matrix to the identity.
- */
- spchome()
- {
- Coord center[3];
- Matrix object_matrix;
-
- compute_center(center);
-
- pushmatrix();
- loadmatrix(identity_matrix);
- translate(-center[0], -center[1], -center[2]);
- getmatrix(object_matrix);
- popmatrix();
-
- update_selected_children(root->child, object_matrix);
- draw_display();
-
- }
-
- #endif
-
-